package com.example.teamilkmall.controller;

import com.example.teamilkmall.controller.vo.PageVO;
import com.example.teamilkmall.controller.vo.ResultVO;
import org.springframework.http.HttpStatus;

import java.util.List;

/**
 * @author wangl
 * @date 2024/10/11
 */
public class BaseController {

    public <T> ResultVO<T> success(T data) {
        ResultVO<T> vo = new ResultVO<>();
        vo.setCode(HttpStatus.OK.value());
        vo.setData(data);
        return vo;
    }

    public ResultVO success() {
        ResultVO vo = new ResultVO();
        vo.setCode(HttpStatus.OK.value());
        return vo;
    }

    /**
     * 分页结果集
     * @param list
     * @param total
     * @return
     */
    public <T> PageVO<List<T>> page(List<T> list, long total){
        PageVO<List<T>> pageVO = new PageVO<>();
        pageVO.setCode(0);
        pageVO.setData(list);
        pageVO.setTotal(total);
        return pageVO;
    }
}